namespace RAG.Application.Commands;

/// <summary>
/// 分页结果类
/// </summary>
/// <typeparam name="T">数据类型</typeparam>
public class PagedResult<T>
{
    /// <summary>
    /// 数据列表
    /// </summary>
    public List<T> Items { get; set; } = new List<T>();

    /// <summary>
    /// 总记录数
    /// </summary>
    public int Total { get; set; }

    /// <summary>
    /// 当前页码
    /// </summary>
    public int Page { get; set; }

    /// <summary>
    /// 每页大小
    /// </summary>
    public int Size { get; set; }

    /// <summary>
    /// 总页数
    /// </summary>
    public int TotalPages { get; set; }

    /// <summary>
    /// 是否有上一页
    /// </summary>
    public bool HasPreviousPage => Page > 1;

    /// <summary>
    /// 是否有下一页
    /// </summary>
    public bool HasNextPage => Page < TotalPages;

    /// <summary>
    /// 构造函数
    /// </summary>
    public PagedResult()
    {
    }

    /// <summary>
    /// 构造函数
    /// </summary>
    /// <param name="items">数据列表</param>
    /// <param name="total">总记录数</param>
    /// <param name="page">当前页码</param>
    /// <param name="size">每页大小</param>
    public PagedResult(List<T> items, int total, int page, int size)
    {
        Items = items;
        Total = total;
        Page = page;
        Size = size;
        TotalPages = (int)Math.Ceiling((double)total / size);
    }

    /// <summary>
    /// 创建分页结果
    /// </summary>
    /// <param name="items">数据列表</param>
    /// <param name="total">总记录数</param>
    /// <param name="page">当前页码</param>
    /// <param name="size">每页大小</param>
    /// <returns>分页结果</returns>
    public static PagedResult<T> Create(List<T> items, int total, int page, int size)
    {
        return new PagedResult<T>(items, total, page, size);
    }
} 